<?php
include '../includes/cDatabase.php';
include '../includes/cPage.php';
include '../includes/cDates.php';

$cPage = new page("Read Captain Log");
echo $cPage->getTitle();
echo $cPage->pageStringStart();
echo $cPage->contentStringStart();

$cDatabase = new database();

$connect = $cDatabase->connectToDatabase();
$activeDatabase = $cDatabase->getActiveDatabase($connect);
	
$db = $cDatabase->selectDatabase($connect, $activeDatabase);

$selectArray[0] = '*';
$result = $cDatabase->selectFromDatabase($connect, 'captainLog', $selectArray, NULL, NULL, NULL, NULL);

if($result == 0)
{
	echo "<b>Error ".mysqli_errno($connect).": ".mysqli_error($connect)."</b>";
}
elseif (@mysqli_num_rows($result) == 0)
{
	echo("<b>Query completed. No results returned.</b><br>");
}
else
{
	echo "<table border='1'><thead><tr>";
	$finfo = mysqli_fetch_fields($result);
	for($i = 0; $i < mysqli_num_fields($result); $i++)
	{
		echo "<th>" .$finfo[$i]->name."</th>";
	}
	echo "  </tr></thead><tbody>";

	for ($i = 0; $i < mysqli_num_rows($result); $i++)
	{
		echo "<tr>";
		$row = mysqli_fetch_row($result);
		for($j = 0; $j < mysqli_num_fields($result); $j++)
	 	{
			echo("<td>" . $row[$j] . "</td>");
		}
		echo "</tr>";
	}
	echo "</tbody>
	</table>";
 }  //end else
echo $cPage->getContentStringEnd();
echo $cPage->getMenu();
echo $cPage->getClear();
echo $cPage->pageStringEnd();
echo $cPage->getFooter();
?>